package com.softeem.ssm2.controller;

import com.softeem.ssm2.dto.Result;
import com.softeem.ssm2.entity.User;
import com.softeem.ssm2.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @Author mrchai
 * @Date 2019/10/16 15:18
 */
@SessionAttributes({"user"})
@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/reg")
    public ModelAndView reg(User user){
        return userService.addUser(user);
    }

    @ResponseBody
    @GetMapping("/login")
    public Result login(ModelMap map, User user){
        Result r = userService.queryByUser(user);
        if(r.isSuccess()){
            map.addAttribute("user",r.getData());
        }
        return r;
    }

}
